import json, strformat, httpclient,os

const config = "config.json"
var jsonNode = json.parseFile(config)
if dirExists("downloads") == false:
  createDir("downloads")

var client = newHttpClient()
client.headers = newHttpHeaders({"User-Agent": "Nim HTTPClient"})
for key, value in jsonNode.pairs:
    echo &"Key: {key}, Value: {value}"
    var url = value.str
    var filename = key
    var filePath = "downloads/" & filename
    try:
        client.downloadFile(url, filePath)
    except HttpRequestError:
        echo "http request error"
        echo getCurrentExceptionMsg()
    except IOError:
        echo "file write error"
        echo getCurrentExceptionMsg()